const Quill = window.Quill;
const BlockEmbed = Quill.import('blots/block/embed');

class VideoBlot extends BlockEmbed {
    static create(value) {
        const node = super.create();
        const video = document.createElement('video');
        
        // 设置视频属性
        video.setAttribute('src', value);
        video.setAttribute('controls', true);
        video.setAttribute('preload', 'metadata');
        
        // 设置视频样式
        video.style.maxWidth = '100%';
        video.style.height = 'auto';
        video.style.marginTop = '10px';
        video.style.marginBottom = '10px';
        video.style.borderRadius = '4px';
        video.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
        
        // 添加视频预览事件
        video.addEventListener('mouseover', () => {
            if (video.paused) {
                video.play().catch(() => {});
                setTimeout(() => {
                    if (!video.paused) video.pause();
                }, 2000);
            }
        });
        
        node.appendChild(video);
        return node;
    }

    static value(node) {
        return node.querySelector('video').getAttribute('src');
    }
}

VideoBlot.blotName = 'video';
VideoBlot.tagName = 'div';
VideoBlot.className = 'ql-video-container';

export default VideoBlot;